home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
BORL_TIP
/
TI1000
/
TI1726.ASC
< prev
next >
Wrap
Text File
|
1993-10-21
|
3KB
|
133 lines
PRODUCT : Borland Pascal NUMBER : 1726
VERSION : All
OS : All
DATE : October 21, 1993 PAGE : 1/2
TITLE : Using procedural varialbles in Pascal
The included program, FUNC1.PAS shows how to use procedural
variables.
It creates both a pointer to a function and a pointer
to a procedure and shows how to use them.
Func1 creates a pointer to a function called MyFunc,
calls it once and then passes it to a procedure which
then proceeds to call it. Therefore this examples shows
how to assign and call a procedural variable, and
also how to pass it to another procedure which
can then call it.
The following lines demonstrate how to create types
that can point at a procedure or function:
type
TMyFunc = function(i: Integer): Integer;
TMyProc = procedure;
Notice that the actual name of the function or procedure
is left out, but that it is necessary to declare any
variables passed to function or procedure, and to specify
any return types from a function.
Its important to understand that TMyFunc and TMyProc are
really pointers to functions, even though there is no
need to call new and dispose, and no need to dereference
the pointer with the caret symbol ("^").
Notice also that both MyProcedure and MyFunc are declared
"Far". This is absolutely necessary when working with
procedural variables, though of course functions declared
in the header to a unit will automatically be far when
called from another module.
program Func1;
type
TMyFunc = function(i: Integer): Integer;
TMyProc = procedure;
PRODUCT : Borland Pascal NUMBER : 1726
VERSION : All
OS : All
DATE : October 21, 1993 PAGE : 2/2
TITLE : Using procedural varialbles in Pascal
procedure MyProcedure; far;
begin
WriteLn('Hi');
end;
function MyFunc(I: Integer): Integer; far;
begin
WriteLn(i);
end;
procedure Foo(F: TMyFunc);
begin
F(5);
end;
var
F: TMyFunc;
P: TMyProc;
begin
F := MyFunc;
F(10);
Foo(F);
P := MyProcedure;
P;
end.
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.